/******************************************************************************
Paper: The Impact of Welfare on Intergroup Relations
Author: Akshay Dixit

Survey: This .do file produces the following supplementary results:
	- Figure S1 and Tables S29-S32 (Controlling for caste)
	- Figure S2 and Tables S33-S36 (Controlling for public goods provision)
	- Figure S3 and Tables S41-S44 (Robustness check for definition of low inequality, using mean instead of median)
	- Figure S6 and Tables S37-S40 (Controlling for respondent characteristics)
	- Figure S10 and Tables S53-S56 (Robustness check for definition of low inequality, using a threshold of 1.5 instead of median)
	- Table S6 (Heterogeneity by travel distance by road to the other state)
	- Table S57 (Effect of welfare on incentivized donation among SC respondents)
******************************************************************************/

clear all
gl data "$identity/data/survey"

* Remove existing .tex files, to be replaced by new ones ***
local datafiles: dir "$analysis/survey_robustness" files "*.tex"
foreach datafile of local datafiles {
        cap erase "$analysis/survey_robustness/`datafile'"
}

u "$data/Household Survey V2_clean.dta", clear

cd "$analysis/survey_robustness"

* Controls
gl controls1 = "hh_size village_population castes_in_village"
gl controls2 = "hh_size village_population castes_in_village other_welfare"

	/* 
	The addition or removal of "other_welfare" as a control doesn't change the results,
	but keep it in the analysis to get at the effect of RBS more precisely.
	*/

*******************************************************************************

*** Create standardized outcomes for analysis ***

local intercaste_behavior share_meal share_meal_others friends_same_caste
foreach var of local intercaste_behavior {	
	qui sum `var' if (telangana == 0)
	g `var'_sd = (`var'-r(mean))/r(sd)
}

qui sum donation if (telangana == 0 & scheduled_caste == 0)
g donation_sd = (donation-r(mean))/r(sd)

*******************************************************************************

*** Control for caste ***

	// Donation: Regression
qui reg donation_sd telangana_ownagriland telangana ownagriland i.q1p11 $controls2 if low_land_inequality == 1 & scheduled_caste == 0, vce(cluster village)
local bdonation_sd_l = _b[telangana_ownagriland]
estimates store e_donation_low

qui reg donation_sd telangana_ownagriland telangana ownagriland i.q1p11 $controls2 if low_land_inequality == 0 & scheduled_caste == 0, vce(cluster village)
local bdonation_sd_h = _b[telangana_ownagriland]
estimates store e_donation_high

	// Other outcomes: Regression
local intercaste_behavior share_meal share_meal_others friends_same_caste
foreach var of local intercaste_behavior {
	
	qui reg `var'_sd telangana_ownagriland telangana ownagriland i.q1p11 $controls2 if low_land_inequality == 1, vce(cluster village)
	local b`var'_sd_l = _b[telangana_ownagriland]
	estimates store e_`var'_low
	
	qui reg `var'_sd telangana_ownagriland telangana ownagriland i.q1p11 $controls2 if low_land_inequality == 0, vce(cluster village)
	local b`var'_sd_h = _b[telangana_ownagriland]
	estimates store e_`var'_high

}

#delimit ;
coefplot (e_donation_low, aseq("Donation (non-SCs)")
		\ e_share_meal_low, aseq("Meals with other castes")
		\ e_share_meal_others_low, aseq("Others have meals with other castes") 
		\ e_friends_same_caste_low, aseq("Most/all friends from own caste"))
	, keep(telangana_ownagriland) xline(0) swapnames title("Lower land inequality", size(medium))
	  xtitle("Effect Size (Standard Deviations)", size(small))
	  xlabel(-0.8(0.2)0.8)
;

graph save intercaste_low, replace;

coefplot (e_donation_high, aseq("Donation (non-SCs)")
		\ e_share_meal_high, aseq("Meals with other castes")
		\ e_share_meal_others_high, aseq("Others have meals with other castes") 
		\ e_friends_same_caste_high, aseq("Most/all friends from own caste"))
	, keep(telangana_ownagriland) xline(0) swapnames title("Higher land inequality", size(medium))
	  xtitle("Effect Size (Standard Deviations)", size(small))
	  xlabel(-0.8(0.2)0.8) yscale(off) fxsize(47.5) mcolor(gs10) ciopts(lcolor(gs10))
;

graph save intercaste_high, replace;

#delimit cr

graph combine "intercaste_low" "intercaste_high", cols(2)

graph export "control for caste.png", as(png) replace
erase intercaste_low.gph
erase intercaste_high.gph
drop _est_e_*


	// Tabular form
qui reg donation telangana_ownagriland telangana ownagriland i.q1p11 $controls2 if low_land_inequality == 1 & scheduled_caste == 0, vce(cluster village)
outreg2 using "control for caste_donation_low.tex", append label nocons nor2 keep(telangana_ownagriland telangana ownagriland hh_size village_population castes_in_village other_welfare)

qui reg donation telangana_ownagriland telangana ownagriland i.q1p11 $controls2 if low_land_inequality == 0 & scheduled_caste == 0, vce(cluster village)
outreg2 using "control for caste_donation_high.tex", append label nocons nor2 keep(telangana_ownagriland telangana ownagriland hh_size village_population castes_in_village other_welfare)

local intercaste_behavior share_meal share_meal_others friends_same_caste
foreach var of local intercaste_behavior {
	
	dis as error "Low inequality"
	qui reg `var' telangana_ownagriland telangana ownagriland i.q1p11 $controls2 if low_land_inequality == 1, vce(cluster village)
	outreg2 using "control for caste_behavior_low.tex", append label nocons nor2 keep(telangana_ownagriland telangana ownagriland hh_size village_population castes_in_village other_welfare)
	
	dis as error "High inequality"
	qui reg `var' telangana_ownagriland telangana ownagriland i.q1p11 $controls2 if low_land_inequality == 0, vce(cluster village)
	outreg2 using "control for caste_behavior_high.tex", append label nocons nor2 keep(telangana_ownagriland telangana ownagriland hh_size village_population castes_in_village other_welfare)

}

*******************************************************************************

*** Control for village-level public goods provision ***

	// Index of public goods provision: Sum of 16 public goods
egen index_public_goods = rowtotal(v_q4p11 v_q4p13 v_q4p14 v_q4p15 v_q4p16 v_q4p23 v_q4p24 v_q4p25 v_q4p26 v_q4p27 v_q4p28 v_q4p29 v_q4p30 v_q4p31 v_q4p32 v_q4p33), missing
tab index_public_goods

gl controls4 = "hh_size village_population castes_in_village other_welfare index_public_goods"

	// Donation: Regression
qui reg donation_sd telangana_ownagriland telangana ownagriland $controls4 if low_land_inequality == 1 & scheduled_caste == 0, vce(cluster village)
local bdonation_sd_l = _b[telangana_ownagriland]
estimates store e_donation_low

qui reg donation_sd telangana_ownagriland telangana ownagriland $controls4 if low_land_inequality == 0 & scheduled_caste == 0, vce(cluster village)
local bdonation_sd_h = _b[telangana_ownagriland]
estimates store e_donation_high

	// Other outcomes: Regression
local intercaste_behavior share_meal share_meal_others friends_same_caste
foreach var of local intercaste_behavior {
	
	qui reg `var'_sd telangana_ownagriland telangana ownagriland $controls4 if low_land_inequality == 1, vce(cluster village)
	local b`var'_sd_l = _b[telangana_ownagriland]
	estimates store e_`var'_low
	
	qui reg `var'_sd telangana_ownagriland telangana ownagriland $controls4 if low_land_inequality == 0, vce(cluster village)
	local b`var'_sd_h = _b[telangana_ownagriland]
	estimates store e_`var'_high

}

#delimit ;
coefplot (e_donation_low, aseq("Donation (non-SCs)")
		\ e_share_meal_low, aseq("Meals with other castes")
		\ e_share_meal_others_low, aseq("Others have meals with other castes") 
		\ e_friends_same_caste_low, aseq("Most/all friends from own caste"))
	, keep(telangana_ownagriland) xline(0) swapnames title("Lower land inequality", size(medium))
	  xtitle("Effect Size (Standard Deviations)", size(small))
	  xlabel(-0.8(0.2)0.8)
;

graph save intercaste_low, replace;

coefplot (e_donation_high, aseq("Donation (non-SCs)")
		\ e_share_meal_high, aseq("Meals with other castes")
		\ e_share_meal_others_high, aseq("Others have meals with other castes") 
		\ e_friends_same_caste_high, aseq("Most/all friends from own caste"))
	, keep(telangana_ownagriland) xline(0) swapnames title("Higher land inequality", size(medium))
	  xtitle("Effect Size (Standard Deviations)", size(small))
	  xlabel(-0.8(0.2)0.8) yscale(off) fxsize(47.5) mcolor(gs10) ciopts(lcolor(gs10))
;

graph save intercaste_high, replace;

#delimit cr

graph combine "intercaste_low" "intercaste_high", cols(2)

graph export "control for public goods.png", as(png) replace
erase intercaste_low.gph
erase intercaste_high.gph
drop _est_e_*

	// Tabular form
qui reg donation telangana_ownagriland telangana ownagriland $controls4 if low_land_inequality == 1 & scheduled_caste == 0, vce(cluster village)
outreg2 using "control for public_donation_low.tex", append label nocons nor2

qui reg donation telangana_ownagriland telangana ownagriland $controls4 if low_land_inequality == 0 & scheduled_caste == 0, vce(cluster village)
outreg2 using "control for public_donation_high.tex", append label nocons nor2

local intercaste_behavior share_meal share_meal_others friends_same_caste
foreach var of local intercaste_behavior {
	
	dis as error "Low inequality"
	qui reg `var' telangana_ownagriland telangana ownagriland $controls4 if low_land_inequality == 1, vce(cluster village)
	outreg2 using "control for public_behavior_low.tex", append label nocons nor2
	
	dis as error "High inequality"
	qui reg `var' telangana_ownagriland telangana ownagriland $controls4 if low_land_inequality == 0, vce(cluster village)
	outreg2 using "control for public_behavior_high.tex", append label nocons nor2

}

*******************************************************************************

*** Control for respondent characteristics ***

gl respondent = "age female education hh_head"

	// Donation: Regression
qui reg donation_sd telangana_ownagriland telangana ownagriland $controls2 $respondent if low_land_inequality == 1 & scheduled_caste == 0, vce(cluster village)
local bdonation_sd_l = _b[telangana_ownagriland]
estimates store e_donation_low

qui reg donation_sd telangana_ownagriland telangana ownagriland $controls2 $respondent if low_land_inequality == 0 & scheduled_caste == 0, vce(cluster village)
local bdonation_sd_h = _b[telangana_ownagriland]
estimates store e_donation_high

	// Other outcomes: Regression
local intercaste_behavior share_meal share_meal_others friends_same_caste
foreach var of local intercaste_behavior {
	
	qui reg `var'_sd telangana_ownagriland telangana ownagriland $controls2 $respondent if low_land_inequality == 1, vce(cluster village)
	local b`var'_sd_l = _b[telangana_ownagriland]
	estimates store e_`var'_low
	
	qui reg `var'_sd telangana_ownagriland telangana ownagriland $controls2 $respondent if low_land_inequality == 0, vce(cluster village)
	local b`var'_sd_h = _b[telangana_ownagriland]
	estimates store e_`var'_high

}

#delimit ;
coefplot (e_donation_low, aseq("Donation (non-SCs)")
		\ e_share_meal_low, aseq("Meals with other castes")
		\ e_share_meal_others_low, aseq("Others have meals with other castes") 
		\ e_friends_same_caste_low, aseq("Most/all friends from own caste"))
	, keep(telangana_ownagriland) xline(0) swapnames title("Lower land inequality", size(medium))
	  xtitle("Effect Size (Standard Deviations)", size(small))
	  xlabel(-0.8(0.2)0.8)
;

graph save intercaste_low, replace;

coefplot (e_donation_high, aseq("Donation (non-SCs)")
		\ e_share_meal_high, aseq("Meals with other castes")
		\ e_share_meal_others_high, aseq("Others have meals with other castes") 
		\ e_friends_same_caste_high, aseq("Most/all friends from own caste"))
	, keep(telangana_ownagriland) xline(0) swapnames title("Higher land inequality", size(medium))
	  xtitle("Effect Size (Standard Deviations)", size(small))
	  xlabel(-0.8(0.2)0.8) yscale(off) fxsize(47.5) mcolor(gs10) ciopts(lcolor(gs10))
;

graph save intercaste_high, replace;

#delimit cr

graph combine "intercaste_low" "intercaste_high", cols(2)

graph export "control for respondent characteristics.png", as(png) replace
erase intercaste_low.gph
erase intercaste_high.gph
drop _est_e_*

	// Tabular form
qui reg donation telangana_ownagriland telangana ownagriland $controls2 $respondent if low_land_inequality == 1 & scheduled_caste == 0, vce(cluster village)
outreg2 using "control for respondent_donation_low.tex", append label nocons nor2

qui reg donation telangana_ownagriland telangana ownagriland $controls2 $respondent if low_land_inequality == 0 & scheduled_caste == 0, vce(cluster village)
outreg2 using "control for respondent_donation_high.tex", append label nocons nor2

local intercaste_behavior share_meal share_meal_others friends_same_caste
foreach var of local intercaste_behavior {
	
	dis as error "Low inequality"
	qui reg `var' telangana_ownagriland telangana ownagriland $controls2 $respondent if low_land_inequality == 1, vce(cluster village)
	outreg2 using "control for respondent_behavior_low.tex", append label nocons nor2
	
	dis as error "High inequality"
	qui reg `var' telangana_ownagriland telangana ownagriland $controls2 $respondent if low_land_inequality == 0, vce(cluster village)
	outreg2 using "control for respondent_behavior_high.tex", append label nocons nor2

}

*******************************************************************************

*** Het. effects by inequality: Defining "low inequality" using the mean dominant_land_to_pop (3)

g low_land_inequality_3 = (dominant_land_to_pop < 3)
replace low_land_inequality_3 = . if dominant_land_to_pop == .

	// Donation: Regression
qui reg donation_sd telangana_ownagriland telangana ownagriland $controls2 if low_land_inequality_3 == 1 & scheduled_caste == 0, vce(cluster village)
local bdonation_sd_l = _b[telangana_ownagriland]
estimates store e_donation_low

qui reg donation_sd telangana_ownagriland telangana ownagriland $controls2 if low_land_inequality_3 == 0 & scheduled_caste == 0, vce(cluster village)
local bdonation_sd_h = _b[telangana_ownagriland]
estimates store e_donation_high

	// Other outcomes: Regression
local intercaste_behavior share_meal share_meal_others friends_same_caste
foreach var of local intercaste_behavior {
	
	qui reg `var'_sd telangana_ownagriland telangana ownagriland $controls2 if low_land_inequality_3 == 1, vce(cluster village)
	local b`var'_sd_l = _b[telangana_ownagriland]
	estimates store e_`var'_low
	
	qui reg `var'_sd telangana_ownagriland telangana ownagriland $controls2 if low_land_inequality_3 == 0, vce(cluster village)
	local b`var'_sd_h = _b[telangana_ownagriland]
	estimates store e_`var'_high

}

#delimit ;
coefplot (e_donation_low, aseq("Donation (non-SCs)")
		\ e_share_meal_low, aseq("Meals with other castes")
		\ e_share_meal_others_low, aseq("Others have meals with other castes") 
		\ e_friends_same_caste_low, aseq("Most/all friends from own caste"))
	, keep(telangana_ownagriland) xline(0) swapnames title("Lower land inequality", size(medium))
	  xtitle("Effect Size (Standard Deviations)", size(small))
	  xlabel(-0.8(0.2)0.8)
;

graph save intercaste_low, replace;

coefplot (e_donation_high, aseq("Donation (non-SCs)")
		\ e_share_meal_high, aseq("Meals with other castes")
		\ e_share_meal_others_high, aseq("Others have meals with other castes") 
		\ e_friends_same_caste_high, aseq("Most/all friends from own caste"))
	, keep(telangana_ownagriland) xline(0) swapnames title("Higher land inequality", size(medium))
	  xtitle("Effect Size (Standard Deviations)", size(small))
	  xlabel(-0.8(0.2)0.8) yscale(off) fxsize(47.5) mcolor(gs10) ciopts(lcolor(gs10))
;

graph save intercaste_high, replace;

#delimit cr

graph combine "intercaste_low" "intercaste_high", cols(2)

graph export "het_inequality_intercaste_behavior_3.png", as(png) replace
erase intercaste_low.gph
erase intercaste_high.gph
drop _est_e_*

	// Tabular form
qui reg donation telangana_ownagriland telangana ownagriland $controls2 if low_land_inequality_3 == 1 & scheduled_caste == 0, vce(cluster village)
outreg2 using "het_inequality_3_no_donation.tex", append label nocons nor2

qui reg donation telangana_ownagriland telangana ownagriland $controls2 if low_land_inequality_3 == 0 & scheduled_caste == 0, vce(cluster village)
outreg2 using "het_inequality_3_yes_donation.tex", append label nocons nor2

local intercaste_behavior share_meal share_meal_others friends_same_caste
foreach var of local intercaste_behavior {
	
	dis as error "Low inequality"
	qui reg `var' telangana_ownagriland telangana ownagriland $controls2 if low_land_inequality_3 == 1, vce(cluster village)
	outreg2 using "het_inequality_3_no_intercaste_behavior.tex", append label nocons nor2
	
	dis as error "High inequality"
	qui reg `var' telangana_ownagriland telangana ownagriland $controls2 if low_land_inequality_3 == 0, vce(cluster village)
	outreg2 using "het_inequality_3_yes_intercaste_behavior.tex", append label nocons nor2

}

********************************************************************************

*** Het. effects by inequality: Defining "low inequality" using a different threshold (1.5)

g low_land_inequality_1_5 = (dominant_land_to_pop < 1.5)
replace low_land_inequality_1_5 = . if dominant_land_to_pop == .

	// Donation: Regression
qui reg donation_sd telangana_ownagriland telangana ownagriland $controls2 if low_land_inequality_1_5 == 1 & scheduled_caste == 0, vce(cluster village)
local bdonation_sd_l = _b[telangana_ownagriland]
estimates store e_donation_low

qui reg donation_sd telangana_ownagriland telangana ownagriland $controls2 if low_land_inequality_1_5 == 0 & scheduled_caste == 0, vce(cluster village)
local bdonation_sd_h = _b[telangana_ownagriland]
estimates store e_donation_high

	// Other outcomes: Regression
local intercaste_behavior share_meal share_meal_others friends_same_caste
foreach var of local intercaste_behavior {
	
	qui reg `var'_sd telangana_ownagriland telangana ownagriland $controls2 if low_land_inequality_1_5 == 1, vce(cluster village)
	local b`var'_sd_l = _b[telangana_ownagriland]
	estimates store e_`var'_low
	
	qui reg `var'_sd telangana_ownagriland telangana ownagriland $controls2 if low_land_inequality_1_5 == 0, vce(cluster village)
	local b`var'_sd_h = _b[telangana_ownagriland]
	estimates store e_`var'_high

}

#delimit ;
coefplot (e_donation_low, aseq("Donation (non-SCs)")
		\ e_share_meal_low, aseq("Meals with other castes")
		\ e_share_meal_others_low, aseq("Others have meals with other castes") 
		\ e_friends_same_caste_low, aseq("Most/all friends from own caste"))
	, keep(telangana_ownagriland) xline(0) swapnames title("Lower land inequality", size(medium))
	  xtitle("Effect Size (Standard Deviations)", size(small))
	  xlabel(-0.8(0.2)0.8)
;

graph save intercaste_low, replace;

coefplot (e_donation_high, aseq("Donation (non-SCs)")
		\ e_share_meal_high, aseq("Meals with other castes")
		\ e_share_meal_others_high, aseq("Others have meals with other castes") 
		\ e_friends_same_caste_high, aseq("Most/all friends from own caste"))
	, keep(telangana_ownagriland) xline(0) swapnames title("Higher land inequality", size(medium))
	  xtitle("Effect Size (Standard Deviations)", size(small))
	  xlabel(-0.8(0.2)0.8) yscale(off) fxsize(47.5) mcolor(gs10) ciopts(lcolor(gs10))
;

graph save intercaste_high, replace;

#delimit cr

graph combine "intercaste_low" "intercaste_high", cols(2)

graph export "het_inequality_intercaste_behavior_1_5.png", as(png) replace
erase intercaste_low.gph
erase intercaste_high.gph
drop _est_e_*

	// Tabular form
qui reg donation telangana_ownagriland telangana ownagriland $controls2 if low_land_inequality_1_5 == 1 & scheduled_caste == 0, vce(cluster village)
outreg2 using "het_inequality_1_5_no_donation.tex", append label nocons nor2

qui reg donation telangana_ownagriland telangana ownagriland $controls2 if low_land_inequality_1_5 == 0 & scheduled_caste == 0, vce(cluster village)
outreg2 using "het_inequality_1_5_yes_donation.tex", append label nocons nor2

local intercaste_behavior share_meal share_meal_others friends_same_caste
foreach var of local intercaste_behavior {
	
	dis as error "Low inequality"
	qui reg `var' telangana_ownagriland telangana ownagriland $controls2 if low_land_inequality_1_5 == 1, vce(cluster village)
	outreg2 using "het_inequality_1_5_no_intercaste_behavior.tex", append label nocons nor2
	
	dis as error "High inequality"
	qui reg `var' telangana_ownagriland telangana ownagriland $controls2 if low_land_inequality_1_5 == 0, vce(cluster village)
	outreg2 using "het_inequality_1_5_yes_intercaste_behavior.tex", append label nocons nor2

}

*******************************************************************************

*** Het. effects by travel distance to state border ***

summ v_q4p6, d
g close = (v_q4p6 <= 5)

g telangana_ownagriland_close = telangana_ownagriland * close
g telangana_close = telangana * close
g ownagriland_close = ownagriland * close

lab var telangana_ownagriland_close "Telangana * Ownagriland * Closer to border"

qui reg donation telangana_ownagriland_close telangana_ownagriland telangana_close ownagriland_close telangana ownagriland close $controls2 if scheduled_caste == 0, vce(cluster village)
outreg2 using "het effects by distance to border.tex", replace label nocons nor2

local intercaste_behavior share_meal share_meal_others friends_same_caste
foreach var of local intercaste_behavior {
	
	qui reg `var' telangana_ownagriland_close telangana_ownagriland telangana_close ownagriland_close telangana ownagriland close $controls2, vce(cluster village)
	outreg2 using "het effects by distance to border.tex", append label nocons nor2

}

*******************************************************************************

*** Analysis of donation outcome for scheduled castes ***

qui summ donation if telangana == 0 & scheduled_caste == 1
local donation_mean = (r(mean))

qui reg donation telangana_ownagriland telangana ownagriland $controls2 if scheduled_caste == 1, vce(cluster village)
outreg2 using "donation_sc.tex", append label nocons nor2 ctitle("Full sample") addstat(Andhra Pradesh mean, `donation_mean') addnote("Controls: Number of HH members, village population, number of castes in village, benefits from welfare programs other than RBS")

qui reg donation telangana_ownagriland telangana ownagriland $controls2 if scheduled_caste == 1 & low_land_inequality == 1, vce(cluster village)
outreg2 using "donation_sc.tex", append label nocons nor2 ctitle("Low inequality") addstat(Andhra Pradesh mean, `donation_mean') addnote("Controls: Number of HH members, village population, number of castes in village, benefits from welfare programs other than RBS")

qui reg donation telangana_ownagriland telangana ownagriland $controls2 if scheduled_caste == 1 & low_land_inequality == 0, vce(cluster village)
outreg2 using "donation_sc.tex", append label nocons nor2 ctitle("High inequality") addstat(Andhra Pradesh mean, `donation_mean') addnote("Controls: Number of HH members, village population, number of castes in village, benefits from welfare programs other than RBS")

*******************************************************************************

local datafiles: dir "$analysis/survey_robustness" files "*.txt"
foreach datafile of local datafiles {
        cap erase "$analysis/survey_robustness/`datafile'"
}

clear

